const path = require("path");
const Koa = require("koa");
const koaRouter = require("koa-router");
const { koaBody } = require("koa-body");
const koaStatic = require("koa-static");
const errHandlers = require("./error.handle");

const Router = new koaRouter();
const IndexRouter = require("../router");
const app = new Koa();
app.use(koaStatic(path.join(__dirname, "../public/upload/")));
app.use(
    koaBody({
        multipart: true,
        formidable: {
            uploadDir: path.join(__dirname, "../public/upload/"), // 设置文件上传目录
            maxFileSize: 500 * 1024 * 1024, // 设置上传文件大小最大限制，默认5M
        },
    })
);
app.use(Router.routes(), Router.allowedMethods());
IndexRouter(app);
app.on("error", errHandlers);
module.exports = app;
